home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / prtfrm51.zip / FRMSRC.ZIP / FDEMO12.PAS < prev    next >
Pascal/Delphi Source File  |  1996-06-20  |  4KB  |  130 lines

  1. unit Fdemo12;
  2.  
  3. interface
  4.  
  5. uses WinTypes, WinProcs, Classes, Graphics, Forms, Controls, Buttons,
  6.   StdCtrls, ExtCtrls, PrnWin, SysUtils, CB_Types;
  7.  
  8. type
  9.   TForm12 = class(TForm)
  10.     Exit: TBitBtn;
  11.     Bevel1: TBevel;
  12.     Label1: TLabel;
  13.     Edit1: TEdit;
  14.     Edit2: TEdit;
  15.     Edit3: TEdit;
  16.     Edit4: TEdit;
  17.     Edit5: TEdit;
  18.     Edit6: TEdit;
  19.     Label4: TLabel;
  20.     PreView: TBitBtn;
  21.     PrintWin1: TPrintWin;
  22.     procedure PreViewClick(Sender: TObject);
  23.     procedure FormActivate(Sender: TObject);
  24.     procedure ExitClick(Sender: TObject);
  25.   private
  26.     { Private declarations }
  27.   public
  28.  end;
  29.  
  30. var
  31.   Form12: TForm12;
  32.  
  33. implementation
  34.  
  35. {$R *.DFM}
  36.  
  37. procedure TForm12.PreViewClick(Sender: TObject);
  38. var
  39.     Total: Real;
  40.    C1, C2, C3, C4, C5, C6: Real;
  41.    x, y: Real;
  42.    x1,y1,x2,y3: Integer;
  43.    CenterX, CenterY, Radius: Real;
  44.    t, l, b, r: Integer;
  45. begin
  46.  
  47.  
  48.     PrintWin1.BeginPrint;
  49.     PrintWin1.SelectSolidBrush (clSilver);
  50.     PrintWin1.NewFont ('Arial', 20, True, TRUE, False);
  51.     PrintWin1.DrawText( 1.6, poCenter, 'The Pie Chart Demo');
  52.     PrintWin1.NewFont ('Arial', 40, False, False, False);
  53.    Total :=  StrToFloat(Edit1.Text) + StrToFloat(Edit2.Text) +
  54.              StrToFloat(Edit3.Text) + StrToFloat(Edit4.Text) +
  55.              StrToFloat(Edit5.Text) + StrToFloat(Edit6.Text);
  56.  
  57.    { Draw the Pie Chart }
  58.    CenterX := 4.0;
  59.    CenterY := 4.0;
  60.    Radius  := 1.6;
  61.  
  62.    PrintWin1.DrawRectAt( Round(CenterX-Radius-0.1),Round(CenterY-Radius-0.1),
  63.                          Round(CenterX+Radius+0.1),Round(CenterY+Radius+0.1));
  64.  
  65.    C1 :=  (2.0*Pi) * (StrToFloat(Edit1.Text)/Total);
  66.    C2 :=  C1+(2.0*Pi) * (StrToFloat(Edit2.Text)/Total);
  67.    C3 :=  C2+(2.0*Pi) * (StrToFloat(Edit3.Text)/Total);
  68.    C4 :=  C3+(2.0*Pi) * (StrToFloat(Edit4.Text)/Total);
  69.    C5 :=  C4+(2.0*Pi) * (StrToFloat(Edit5.Text)/Total);
  70.    C6 :=  C5+(2.0*Pi) * (StrToFloat(Edit6.Text)/Total);
  71.  
  72.    { Start at 0 }
  73.    x := Radius * Cos(C1);   y := Radius * Sin(C1);
  74.    x1 := 300;            y1 := 0;
  75.    PrintWin1.SelectSolidBrush(RGB(255,0,0));
  76.    t := Round(CenterY-Radius);
  77.    l := Round(CenterX-Radius);
  78.    b := Round(CenterY+Radius);
  79.    r := Round(CenterX+Radius);
  80.  
  81.    x1 := Round(CenterX)+Round(Radius);  y1 := Round(CenterY);
  82.    PrintWin1.DrawPie(l,t,r,b,   x1,y1,Round(CenterX)+Round(x),Round(CenterY)-Round(y));
  83.  
  84.    PrintWin1.SelectSolidBrush(RGB(255,255,0));
  85.    x1 := Round(CenterX)+Round(x);  y1 := Round(CenterY)-Round(y);
  86.    x := Radius * Cos(C2);   y := Radius * Sin(C2);
  87.    PrintWin1.DrawPie(l,t,r,b,x1,y1,Round(CenterX)+Round(x),Round(CenterY)-Round(y));
  88.  
  89.    PrintWin1.SelectSolidBrush(RGB(0,255,0));
  90.    x1 := Round(CenterX)+Round(x);  y1 := Round(CenterY)-Round(y);
  91.    x := Radius * Cos(C3);   y := Radius * Sin(C3);
  92.    PrintWin1.DrawPie(l,t,r,b,x1,y1,Round(CenterX)+Round(x),Round(CenterY)-Round(y));
  93.  
  94.    PrintWin1.SelectSolidBrush(RGB(0,255,255));
  95.    x1 := Round(CenterX)+Round(x);  y1 := Round(CenterY)-Round(y);
  96.    x := Radius * Cos(C4);   y := Radius * Sin(C4);
  97.    PrintWin1.DrawPie(l,t,r,b,x1,y1,Round(CenterX)+Round(x),Round(CenterY)-Round(y));
  98.  
  99.    PrintWin1.SelectSolidBrush(RGB(0,0,255));
  100.    x1 := Round(CenterX)+Round(x);  y1 := Round(CenterY)-Round(y);
  101.    x := Radius * Cos(C5);   y := Radius * Sin(C5);
  102.    PrintWin1.DrawPie(l,t,r,b,x1,y1,Round(CenterX)+Round(x),Round(CenterY)-Round(y));
  103.  
  104.    PrintWin1.SelectSolidBrush(RGB(255,0,255));
  105.    x1 := Round(CenterX)+Round(x);  y1 := Round(CenterY)-Round(y);
  106.    x := Radius * Cos(C6);   y := Radius * Sin(C6);
  107.    PrintWin1.DrawPie(l,t,r,b,x1,y1,Round(CenterX)+Round(x),Round(CenterY)-Round(y));
  108.  
  109.    PrintWin1.SelectSolidBrush(RGB(192,192,192));
  110.  
  111.     PrintWin1.EndPrint;
  112. end;
  113.  
  114. procedure TForm12.FormActivate(Sender: TObject);
  115. begin
  116.     Edit1.Text := '45';
  117.    Edit2.Text := '300';
  118.    Edit3.Text := '75';
  119.     Edit4.Text := '100';
  120.    Edit5.Text := '33';
  121.    Edit6.Text := '200';
  122. end;
  123.  
  124. procedure TForm12.ExitClick(Sender: TObject);
  125. begin
  126.     Close;
  127. end;
  128.  
  129. end.
  130.